﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Unis.Framework.Core.Utility;

using KingRoad.EPM.CompletionMaterialsEntity.Model;
using KingRoad.EPM.CompletionMaterialsDAL.BcdVolumeDirectoryService;

namespace KingRoad.EPM.CompletionMaterialsBLL.UIRules
{
    /// <summary> 
    /// 卷内目录表UIRule
    /// </summary> 
    public class BcdVolumedirectoryUIRule
    {
        private readonly IBcdVolumedirectoryService _bcdVolumedirectoryService;
        
        
        public BcdVolumedirectoryUIRule(){}
        
        /// <summary> 
        /// construct function... 
        /// </summary> 
        public BcdVolumedirectoryUIRule(IBcdVolumedirectoryService  bcdVolumedirectoryService)
        {
           _bcdVolumedirectoryService=bcdVolumedirectoryService;
        }

        /// <summary>
        /// 根据条件获取信息
        /// </summary>
        /// <returns></returns>
        public List<BcdVolumedirectoryInfo> GetEntityListBySql(string sql)
        {
            var ret = _bcdVolumedirectoryService.GetEntityList(sql);
            return ret;
        }
        /// <summary>
        /// 根据条件分页查询信息
        /// </summary>
        /// <param name="numCurrentPage">当前页</param>
        /// <param name="numPerPage">每页数据大小</param>
        /// <param name="orderByField">排序字段名称</param>
        /// <param name="totalRecord">总数据量</param>
        /// <param name="sqlCondition">sql查询条件</param>
        /// <param name="desc">排序方式</param>
        /// <returns></returns>
        public List<BcdVolumedirectoryInfo> GetEntityListByContionRe(int numCurrentPage, int numPerPage,
                                                                        string orderByField, out int totalRecord, string sqlCondition, string desc,string table="")
        {
            var list = _bcdVolumedirectoryService.GetEntityListByContionRe(numCurrentPage, numPerPage, orderByField, out totalRecord, sqlCondition, desc,table);
            return list;
        }
        /// <summary>
        /// 查看
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public BcdVolumedirectoryInfo GetEntityById(Guid id)
        {
            var ret = _bcdVolumedirectoryService.GetEntityById(id);
            return ret;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool InsertEntity(BcdVolumedirectoryInfo entity)
        {
            var ret = _bcdVolumedirectoryService.InsertEntity(entity);
            return ret > 0;
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool UpdateEntity(BcdVolumedirectoryInfo entity)
        {
            var ret = _bcdVolumedirectoryService.UpdateEntity(entity);
            return ret > 0;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteEntity(string id)
        {
            var ret = _bcdVolumedirectoryService.DeleteEntityByStringID(id);
            return ret > 0;
        }

        /// <summary>
        /// 根据案卷ID删除卷内目录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteByFlID(string id)
        {
            var ret = _bcdVolumedirectoryService.DeleteByFlID(id);
            return ret > 0;
        }

        /// <summary>
        /// 根据项目ID，材料类型ID删除与之关联的材料
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteByPidFdid(string P_ID, string Fd_ID)
        {
            var ret = _bcdVolumedirectoryService.DeleteByPidFdid(P_ID, Fd_ID);
            return ret > 0;
        }

        /// <summary>
        /// 判断是否存在AssisId
        /// </summary>
        /// <param name="assisId"></param>
        /// <returns></returns>
        public bool IsExitAssistId(int assisId)
        {
            var strSql = String.Format(" Assist_ID={0} ", assisId);
            var list = _bcdVolumedirectoryService.GetEntityList(strSql);
            return list.Any();
        }

        /// <summary>
        /// 拆出文件
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool SplitVolume(string id)
        {
            var ret = _bcdVolumedirectoryService.SplitVolume(id);
            return ret > 0;
        }

        /// <summary>
        /// 审批
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool CheckObject(BcdVolumedirectoryInfo entity)
        {
            var ret = _bcdVolumedirectoryService.CheckObject(entity);
            return ret > 0;
        }
        /// <summary>
        /// 根据项目id，文档类型id 获取该项目此文档类型下未归档文件个数
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public int GetCountBySql(string sql = " 1=1 ")
        {
            var ret = _bcdVolumedirectoryService.GetCountBySql(sql);
            return ret;
        }
    }
}

